﻿cmake_minimum_required(VERSION 3.0.0)

# 获取当前文件夹路径
get_filename_component(CURRENT_DIR ${CMAKE_CURRENT_LIST_FILE} DIRECTORY)

# 获取文件夹名称
get_filename_component(FOLDER_NAME ${CURRENT_DIR} NAME)

# 打印文件夹名称
#message("当前文件夹名称: ${FOLDER_NAME}")

project(${FOLDER_NAME} VERSION 1.1.0 LANGUAGES C CXX)

file(GLOB_RECURSE header_list ${CMAKE_CURRENT_SOURCE_DIR}/*.h)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} ALL_SOURCE)



# 添加头文件路径
include_directories(
    ${PROJECT_SOURCE_DIR}/inc
    ${PROJECT_SOURCE_DIR}/../nebulaWeaver/inc
    ${PROJECT_SOURCE_DIR}/../nebulaWeaver/inc/utils
    ${PROJECT_SOURCE_DIR}/../nebulaWeaver/inc/basic
    ${PROJECT_SOURCE_DIR}/../nebulaWeaver/inc/thread
    ${PROJECT_SOURCE_DIR}/../nebulaWeaver/inc/task
    ${PROJECT_SOURCE_DIR}/../nebulaWeaver/inc/queue
    ${PROJECT_SOURCE_DIR}/googletest/googletest/include
    )

add_executable(${PROJECT_NAME}
    ${ALL_SOURCE}
    )

#指定链接路径
target_link_directories(${PROJECT_NAME} PRIVATE
    ${PROJECT_SOURCE_DIR}/../nebulaWeaverLib/
    )

target_link_libraries(${PROJECT_NAME} nebulaWeaver gtest_main)

# add a "test" target:
enable_testing()

# does the tests pass?情形1
#add_test(UnitTests ${PROJECT_NAME})


#情形2
file(GLOB_RECURSE TEST_CPPS "${PROJECT_SOURCE_DIR}/tests/*test.cpp")

foreach (test_source ${TEST_CPPS})
    # Create a human readable name.
    get_filename_component(test_filename ${test_source} NAME)
    string(REPLACE ".cpp" "" mySTL_test_name ${test_filename})

    # Add the test target separately and as part of "make check-tests".
    add_executable(${mySTL_test_name}  ${test_source})
    target_link_libraries(${mySTL_test_name} GTest::gtest_main)


    gtest_discover_tests(${mySTL_test_name}
            EXTRA_ARGS
            --gtest_color=auto
            --gtest_output=xml:${CMAKE_BINARY_DIR}/test/${mySTL_test_name}.xml
            --gtest_catch_exceptions=0
            DISCOVERY_TIMEOUT 120
            PROPERTIES
            TIMEOUT 120
            )

    # Set test target properties and dependencies.
    set_target_properties(${mySTL_test_name}
            PROPERTIES
            RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/test"
            COMMAND ${mySTL_test_name}
            )
endforeach ()





